<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../css/plant.css">
    <link rel="stylesheet" href="../css/zjy.css">
    <script src="../lib/bootstrap-3.3.5-dist/js/jquery-1.11.3.js"></script>
    <script src="../lib/bootstrap-3.3.5-dist/js/bootstrap.min.js"></script>
    <style>

    </style>
</head>

<body>
    <div class="mydiv">
        <span>新增肉类</span>
    </div>
    <table id="information" cellspacing='0'>
        <!-- <tr>
            <td>商品编号</td>
            <td><input type="text"></td>
        </tr> -->
        <tr>
            <td>商品名称</td>
            <td>
                <!-- <input type="text"> -->
                <select name="" id="m_name">
                    <option value="13">猪</option>
                    <option value="14">鸡</option>
                    <option value="15">鸭</option>
                    <option value="16">鱼</option>
                    <option value="17">鹅</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>商品图片</td>
            <td>
                <input type="file" id="picture">
                <button id='picbut'>上传</button>
                <canvas id='piccan'></canvas>
            </td>
        </tr>
        <tr>
            <td>养殖方式</td>
            <td>
                <select name="" id="g_way">
                    <option value="1">圈养</option>
                    <option value="2">散养</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>出产地</td>
            <td>
                <!-- <input type="text"> -->
                <select name="" id="m_place">
                    <option value="1">四川省成都市高新区云华路133号</option>
                    <option value="2">四川省成都市高新区云华路134号</option>
                    <option value="3">四川省成都市高新区云华路135号</option>
                    <option value="4">四川省成都市高新区云华路136号</option>
                    <option value="5">四川省成都市高新区云华路137号</option>
                    <option value="6">四川省成都市高新区云华路138号</option>
                    <option value="7">四川省成都市高新区云华路139号</option>
                    <option value="8">四川省成都市高新区云华路140号</option>
                    <option value="9">四川省成都市高新区云华路141号</option>
                    <option value="10">四川省成都市高新区云华路142号</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>出栏时间</td>
            <td><input type="date" id="vtime"></td>
        </tr>
        <tr>
            <td>检疫合格证</td>
            <td>
                <input type="file" id="coa">
                <button id='coabut'>上传</button>
                <canvas id='coacan'></canvas>
            </td>
        </tr>
    </table>
    <div class="mydiv but">
        <button id="back">返回</button>
        <button id="confirm">确认</button>
    </div>
</body>
<script src="../js/plant.js"></script>
<script>
    $('#back').click(() => {
        window.location = './farming.html'
    })
    $("#picbut").click(() => {
        $("#picture").click()
    })
    $("#coabut").click(() => {
        $("#coa").click()
    })
    const oc1 = document.getElementById('piccan');
    const oc2 = document.getElementById('coacan');
    showupload($("#picture"), oc1)
    showupload($("#coa"), oc2)
    $("#confirm").click(function () {
        $.ajax({
            url: '/plant/add',
            method: 'post',
            data: {
                sql: `INSERT  INTO goods(g_id,g_class,g_pic,g_place,g_time,g_card,g_way,g_source,g_sup,v_kind) VALUES 
                (null,${$("#m_name").val()},'../images/goods/zhu.png',${$("#m_place").val()},'${$("#vtime").val()}','../images/goods/jianyi.png',${$("#g_way").val()},'自产',NULL,null)`,
            },
            success: function (res) {
                myuplod(oc1, res.myid[0].g_id, 'g_pic', 2)
                myuplod(oc2, res.myid[0].g_id, 'g_card', 2)
            },
            error: function (err) {
                console.log(err)
            }
        })
    })
</script>

</html>